//
//  ZCAVPlayerView.swift
//  weibo
//
//  Created by Ning Xie on 16/8/15.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import AVFoundation

class ZCAVPlayerView: UIView {

    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect) {
        // Drawing code
    }
    */
    
    /*
     let videoURL = NSURL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
     let player = AVPlayer(URL: videoURL!)
     let playerLayer = AVPlayerLayer(player: player)
     playerLayer.frame = self.view.bounds
     self.view.layer.addSublayer(playerLayer)
     player.play()
     
     */
    var videoURL:String?
    
    private  var player : AVPlayer{
        
        let videoURL = NSURL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
        let player = AVPlayer(URL: videoURL!)
        let playerLayer = AVPlayerLayer(player: player)
        playerLayer.frame = self.bounds
        self.layer.addSublayer(playerLayer)
        
        return player
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        
        
        let playBtn = UIButton(type: UIButtonType.Custom)
        playBtn.backgroundColor = UIColor.blueColor()
        playBtn.userInteractionEnabled = true
        
//        bringSubviewToFront(playBtn)
        playBtn.addTarget(self, action: #selector(ZCAVPlayerView.play), forControlEvents: .TouchDown)
        
        self.addSubview(playBtn)
        
        playBtn.snp_makeConstraints { (make) in
            
            make.center.equalTo(self)
            make.size.equalTo(CGSizeMake(30, 30))
        }
        
        
    }
    @objc private func play(){
        
        print("我被点击了")
        player.play()
    }
   

}
